/* eslint-disable @typescript-eslint/no-var-requires */
const esbuild = require('esbuild');
const watchMod = process.argv.indexOf('--watch') >= 0;
// const sassPlugin = require('esbuild-plugin-sass');
const { vanillaExtractPlugin } = require('@vanilla-extract/esbuild-plugin');

Promise.all([
	esbuild.build({
		entryPoints: ['src/index.ts'],
		mainFields: ['browser', 'module', 'main'],
		bundle: true,
		minify: !watchMod,
		platform: 'browser',
		outdir: 'dist',
		watch: watchMod,
		sourcemap: watchMod,
		logLevel: 'info',
		jsx: 'transform',
		jsxFactory: 'h',
		jsxFragment: 'fragment',
		plugins: [
			/* sassPlugin(), */ vanillaExtractPlugin({
				esbuildOptions: {
					loader: { '.svg': 'text' },
				},
			}),
		],
		loader: {
			'.svg': 'text',
		},
	}),
]).catch(() => process.exit(1));
